package com.softlab.logsystem.api;

import com.softlab.logsystem.common.RestData;
import com.softlab.logsystem.common.util.JsonUtil;
import com.softlab.logsystem.core.model.LogDto;
import com.softlab.logsystem.service.ProducerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiXiwen
 * @date 2020/1/7 14:48
 */
@CrossOrigin(origins = "*", allowCredentials = "true", allowedHeaders = "*")
@RestController
public class ProducerApi {
    private static final Logger logger = LoggerFactory.getLogger(ProducerApi.class);

    private final ProducerService producerService;

    @Autowired
    public ProducerApi(ProducerService producerService) {
        this.producerService = producerService;
    }

    /**
     * 发送对象消息
     * @param logDto
     * @return
     */
    @RequestMapping(value = "/send", method = RequestMethod.POST)
    public RestData sendObjectMessage(@RequestBody LogDto logDto) {
        logger.info("POST sendObjectMessage : " + JsonUtil.getJsonString(logDto));
        return producerService.sendlogDto(logDto);
    }

}
